package connect;

import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
import org.apache.mina.filter.codec.ProtocolEncoderOutput;

import util.ByteBuffer;

public class MyEnCoder extends ProtocolEncoderAdapter{

	@Override
    public void encode(IoSession session, Object data, ProtocolEncoderOutput out)
            throws Exception
    {
		
		if(data instanceof ByteBuffer)
		{
			ByteBuffer bb = (ByteBuffer) data;
			IoBuffer buffer = IoBuffer.allocate(bb.getEffective() + 4);
//			buffer.putInt(bb.getEffective());
			buffer.put(bb.getBytes(),0,bb.getEffective());
			buffer.flip();
			out.write(buffer);
		}
		
		
		
    }

		
}
